// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-11-13

package conf

const (
    DefaultKafkaLoggerAddresses = "127.0.0.1:9092"
    DefaultKafkaLoggerTopic     = "go-logs"

    DefaultKafkaLoggerDialTimeout  = 5
    DefaultKafkaLoggerReadTimeout  = 5
    DefaultKafkaLoggerWriteTimeout = 5
)

// KafkaAdapterConfig
// is a component for kafka.
type KafkaAdapterConfig struct {
    // Addresses
    // is kafka clusters address.
    Addresses []string `yaml:"addresses"`

    // Topic
    // log published to.
    //
    //   Default: go-logs
    Topic string `yaml:"topic"`

    DialTimeout   int    `yaml:"dial-timeout"`
    ReadTimeout   int    `yaml:"read-timeout"`
    WriteTimeout  int    `yaml:"write-timeout"`
    ClientVersion string `yaml:"client-version"`
}

// +---------------------------------------------------------------------------+
// | Access methods                                                            |
// +---------------------------------------------------------------------------+

func (o *KafkaAdapterConfig) init() {
    if len(o.Addresses) == 0 {
        o.Addresses = []string{DefaultKafkaLoggerAddresses}
    }
    if o.Topic == "" {
        o.Topic = DefaultKafkaLoggerTopic
    }
    if o.DialTimeout == 0 {
        o.DialTimeout = DefaultKafkaLoggerDialTimeout
    }
    if o.ReadTimeout == 0 {
        o.ReadTimeout = DefaultKafkaLoggerReadTimeout
    }
    if o.WriteTimeout == 0 {
        o.WriteTimeout = DefaultKafkaLoggerWriteTimeout
    }
}
